package com.example.config;

import com.example.schedule.ScheduleRepository;
import com.example.schedule.entity.Schedule;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * @author wangbin
 */
@Configuration
public class ScheduleConfiguration {
    @Bean
    public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
        return new ThreadPoolTaskScheduler();
    }

    @Bean
    CommandLineRunner runner(ScheduleRepository repository) {
        return args -> {
            // name开头字母要用小写，因为需要用这个值找bean
            Schedule schedule1 = new Schedule(1, "testSchedule1", "0/5 * * * * *");
            repository.save(schedule1);
            Schedule schedule2 = new Schedule(2, "testSchedule2", "0/5 * * * * *");
            repository.save(schedule2);
        };
    }
}
